home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / misc / vinced / include / examples / tbitest.c < prev   
C/C++ Source or Header  |  1999-04-19  |  6KB  |  198 lines

  1.  
  2.  
  3. /*  Titlebar.image test (7.9.98)  */
  4. /*  Written for SAS/C             */
  5. /*  Compile: SC LINK TBITest      */
  6. /*  © 1998 Massimo Tantignone     */
  7. /*  e-mail: tanti@intercom.it     */
  8.  
  9.  
  10. #include "exec/types.h"
  11. #include "dos/dos.h"
  12. #include "intuition/intuition.h"
  13. #include "intuition/gadgetclass.h"
  14. #include "intuition/imageclass.h"
  15. #include "libraries/gadtools.h"
  16. #include "proto/intuition.h"
  17. #include "proto/exec.h"
  18.  
  19. #include <images/titlebar.h>
  20. #include <clib/titlebarimage_protos.h>
  21. #include <pragmas/titlebarimage_pragmas.h>
  22.  
  23.  
  24. /* The library base for the "titlebar.image" class library */
  25.  
  26. struct Library *TitlebarImageBase;
  27.  
  28.  
  29. ULONG main(void)
  30. {
  31.    /* The usual stuff */
  32.  
  33.    struct Screen *scr;
  34.    struct Window *win;
  35.    struct IntuiMessage *imsg;
  36.    struct DrawInfo *dri;
  37.    ULONG class, code, fine = FALSE;
  38.    ULONG width = 640, height = 200;
  39.    struct Gadget *gad;
  40.    struct Image *i;
  41.  
  42.    /* Let's try to open the "titlebar.image" library any way we can */
  43.  
  44.    TitlebarImageBase = OpenLibrary("titlebar.image",40L);
  45.  
  46.    if (!TitlebarImageBase)
  47.       TitlebarImageBase = OpenLibrary("Images/titlebar.image",40L);
  48.  
  49.    if (!TitlebarImageBase)
  50.       TitlebarImageBase = OpenLibrary("Classes/Images/titlebar.image",40L);
  51.  
  52.    /* Really not found? Then quit (and complain a bit) */
  53.  
  54.    if (!TitlebarImageBase) return (RETURN_FAIL);
  55.  
  56.    /* Inquire about the real screen size */
  57.  
  58.    if (scr = LockPubScreen(NULL))
  59.    {
  60.       width = scr->Width;
  61.       height = scr->Height;
  62.       UnlockPubScreen(NULL,scr);
  63.    }
  64.  
  65.    /* Open a window on the default public screen */
  66.  
  67.    if (win = OpenWindowTags(NULL,WA_Left,(width - 400) / 2,
  68.                                  WA_Top,(height - 250) / 2,
  69.                                  WA_Width,400,WA_Height,250,
  70.                                  WA_CloseGadget,TRUE,
  71.                                  WA_DepthGadget,TRUE,
  72.                                  WA_SizeGadget,TRUE,
  73.                                  WA_DragBar,TRUE,
  74.                                  WA_SimpleRefresh,TRUE,
  75.                                  WA_Activate,TRUE,
  76.                                  WA_Title,"titlebar.image test",
  77.                                  WA_IDCMP,IDCMP_CLOSEWINDOW |
  78.                                           IDCMP_REFRESHWINDOW,
  79.                                  TAG_END))
  80.    {
  81.       /* Get the screen's DrawInfo, it will be useful... */
  82.  
  83.       if (dri = GetScreenDrawInfo(win->WScreen))
  84.       {
  85.          ULONG a, b, t = 0L;
  86.  
  87.          /* Show the various image types */
  88.  
  89.          for (a = 0; a < 3; a++)
  90.          {
  91.             for (b = 0; b < 2; b++)
  92.             {
  93.                if (i = NewObject(NULL,"tbiclass",SYSIA_Which,POPUPIMAGE + t++,
  94.                                                  SYSIA_DrawInfo,dri,
  95.                                                  TAG_END))
  96.                {
  97.  
  98.                   DrawImageState(win->RPort,i,
  99.                                  50 + a * 100,50 + b * 100,
  100.                                  IDS_NORMAL,dri);
  101.  
  102.                   DrawImageState(win->RPort,i,
  103.                                  50 + a * 100 + 40,50 + b * 100,
  104.                                  IDS_SELECTED,dri);
  105.  
  106.                   DrawImageState(win->RPort,i,
  107.                                  50 + a * 100,50 + b * 100 + 40,
  108.                                  IDS_INACTIVENORMAL,dri);
  109.  
  110.                   DrawImageState(win->RPort,i,
  111.                                  50 + a * 100 + 40,50 + b * 100 + 40,
  112.                                  IDS_INACTIVESELECTED,dri);
  113.  
  114.                   WaitBlit();
  115.  
  116.                   DisposeObject(i);
  117.                }
  118.             }
  119.          }
  120.  
  121.          /* Create an instance of the "tbiclass" image class */
  122.  
  123.          if (i = NewObject(NULL,"tbiclass",SYSIA_Which,ICONIFYIMAGE,
  124.                                            SYSIA_DrawInfo,dri,
  125.                                            TAG_END))
  126.          {
  127.             /* Attempt to create a gadget and add it to the titlebar */
  128.             /* Of course it will use our new "tbiclass" image        */
  129.  
  130.             if (gad = NewObject(NULL,"buttongclass",
  131.                                      GA_RelRight,1 - (3 * (i->Width - 1)),
  132.                                      GA_Top,0,
  133.                                      GA_Width,i->Width - 1,
  134.                                      GA_Height,i->Height,
  135.                                      GA_TopBorder,TRUE,
  136.                                      GA_Image,i,
  137.                                      TAG_END))
  138.             {
  139.                AddGList(win,gad,0,1,NULL);
  140.                RefreshGList(gad,win,NULL,1);
  141.             }
  142.  
  143.             /* Now let's handle the events until the window gets closed */
  144.  
  145.             while (!fine)
  146.             {
  147.                Wait(1 << win->UserPort->mp_SigBit);
  148.  
  149.                while (imsg = (struct IntuiMessage *)GetMsg(win->UserPort))
  150.                {
  151.                   class = imsg->Class;
  152.                   code = imsg->Code;
  153.                   ReplyMsg((struct Message *)imsg);
  154.  
  155.                   if (class == IDCMP_CLOSEWINDOW) fine = TRUE;
  156.  
  157.                   if (class == IDCMP_REFRESHWINDOW)
  158.                   {
  159.                      BeginRefresh(win);
  160.                      EndRefresh(win,TRUE);
  161.                   }
  162.                }
  163.             }
  164.  
  165.             /* If the gadget was added, remove it and free it */
  166.  
  167.             if (gad)
  168.             {
  169.                RemoveGList(win,gad,1);
  170.                DisposeObject(gad);
  171.             }
  172.  
  173.             /* Free the image */
  174.  
  175.             DisposeObject(i);
  176.          }
  177.  
  178.          /* Release the DrawInfo structure */
  179.  
  180.          FreeScreenDrawInfo(win->WScreen,dri);
  181.       }
  182.  
  183.       /* Say good-bye to the window... */
  184.  
  185.       CloseWindow(win);
  186.    }
  187.  
  188.    /* ... and to the library */
  189.  
  190.    CloseLibrary(TitlebarImageBase);
  191.  
  192.    /* We did our job, now let's go home :-) */
  193.  
  194.    return (RETURN_OK);
  195. }
  196.  
  197.  
  198.